/*
* since this is proxy server set a pre-append debug flag to know which debug msgs are coming from where
*/
-
if( !mwApiProxyConfig )
var mwApiProxyConfig = {};
'master_blacklist' : []
};
//user_white_list should also be checked and configured at runtime.
-
js2AddOnloadHook( function() {
//build our configuration from the default and mwApiProxyConfig vars
- mwApiProxyConfig = $j.extend(true, mwApiProxyDefaultConfig, mwApiProxyConfig);
-
+ mwApiProxyConfig = $j.extend(true, mwApiProxyDefaultConfig, mwApiProxyConfig);
$j.apiProxy( 'server', mwApiProxyConfig );
});
'local_wiki_api_url': wgServer + wgScriptPath + '/api.php'
};
-
js2AddOnloadHook( function() {
var amwConf = $j.extend( true, defaultAddMediaConfig, mwAddMediaConfig );
// kind of tricky, it would be nice to use run on ready "loader" call here
+ var didWikiEditorBind = false;
if( typeof $j.wikiEditor != 'undefined' ) {
$j( 'textarea#wpTextbox1' ).bind( 'wikiEditor-toolbar-buildSection-main',
function( e, section ) {
+ didWikiEditorBind = true;
if ( typeof section.groups.insert.tools.file !== 'undefined' ) {
section.groups.insert.tools.file.action = {
'type': 'callback',
$j( '#btn-add-media-wiz' ).addMediaWiz(
amwConf
);
+ }else{
+ //make sure the wikieditor got binded:
+ if( !didWikiEditorBind )
+ $j(".tool [rel='file']").addMediaWiz( amwConf );
}
- },100)
+ }, 120)
});
'url' : $j('#wpUploadFileURL').val(),
'filename' : $j('#wpDestFile').val(),
'comment' : $j('#wpUploadDescription').val(),
- 'watch' : ($j('#wpWatchthis').is(':checked'))?'true':'false'
- }
- //set up ignore warnings and watch arguments:
- if( $j('#wpIgnoreWarning').is(':checked') ){
- httpUpConf[ 'ignorewarnings'] = 'true';
- }
- if( $j('#wpWatchthis').is(':checked') ){
- httpUpConf[ 'watch'] = 'true';
- }
+ 'watch' : ($j('#wpWatchthis').is(':checked'))?'true':'false',
+ 'ignorewarnings': ($j('#wpIgnoreWarning').is(':checked'))?'true':'false'
+ }
//check for editToken
_this.etoken = $j("#wpEditToken").val();
_this.doHttpUpload( httpUpConf );
'asyncdownload' : true //do async download
};
//set config from options:
- for(var i in opt){
- req[i]= opt[i];
- }
+ $j.extend(req, opt);
//else try and get a token:
if(!_this.etoken && _this.api_url){
}
}
//set the upload target name if unset
- if( _this.upload_api_target == 'local' && ! _this.upload_api_name && wgSiteName)
+ if( _this.upload_api_target == 'local' && ! _this.upload_api_name && typeof wgSiteName != 'undefined')
_this.upload_api_name = wgSiteName;
}
},
//issue a api request & cache the result
- //this check can be avoided by setting the this.import_url_mode = 'api' | 'form' | insted of 'autodetect' or 'none'
+ //this check can be avoided by setting the this.import_url_mode = 'api' | 'form' | instead of 'autodetect' or 'none'
checkForCopyURLSupport:function ( callback ){
var _this = this;
js_log('checkForCopyURLSupport:: ');
'data':reqObj,
'url':this.local_wiki_api_url
}, function(data){
- //@@todo propogate the rObj
+ //@@todo propagate the rObj
var rObj = {};
}
);
})
},
- /*set-up the control actions for clipEdit with relevent callbacks */
+ /*set-up the control actions for clipEdit with relevant callbacks */
getClipEditControlActions:function( cp ){
var _this = this;
var cConf= {};
js_log("do preview asset");
//load the preview text:
_this.getParsedWikiText( $j('#rsd_import_ta').val(), _this.cFileNS +':'+ rObj.target_resource_title, function( o ){
- js_log('got updated preivew: ');
+ js_log('got updated preview: ');
$j('#rsd_import_desc').html(o);
});
});
{
'server_frame' : _this.upload_api_proxy_frame,
},function(){
- //now that the api is setup call actual import
+ //now that the api loaded call actual import
debugger;
}
);
*/
loadGM({
- "mwe-setting-up-proxy": "Setting up proxy"
+ "mwe-setting-up-proxy" : "Setting up proxy",
+ "mwe-re-try" : "Retry Api request",
+ "mwe-re-trying": "Retrying api request",
+ "mwe-cancel" : "Cancel",
+ "mwe-proxy-not-ready": "Proxy is not configured",
+ "mwe-please-login" : "Please <a target=\"_new\" href=\"$1\">loggin</a> and or enable mwEmbed and retry the request",
+ "mwe-remember-loging": "As a genneral sequirty reminder. Only login to web sites when your address bar displayes that sites address"
});
(function( $ ) {
$.proxy = {};
/**
- * The clientApiProxy handles a request to external server
- *
- * This is (Domain A) in the above described setup
+ * The client setup function:
*/
- $.proxy.client = function( pConf, callback ){
+ $.proxy.client = function( pConf, conf ){
var _this = this;
//do setup:
if( pConf.server_frame )
if( pConf.client_frame_path )
$.proxy.client_frame_path = pConf.client_frame_path;
-
- //setup a dialog to manage proxy setup:
- $j.addLoaderDialog( gM('mwe-setting-up-proxy') );
-
+
if( parseUri( $.proxy.server_frame).host == parseUri( document.URL ).host ){
- js_log("Error: why are you trying to proxy yourself? " );
- return false;
- }
- //add an iframe to domain B with request for proxy just do the setup
- $.proxy.doFrameProxy( { 'init' : 'echo' } );
-
- //if we have a setup callback
- $.proxy.callback = callback;
+ js_log("Error: why are you trying to proxy yourself? " );
+ return false;
+ }
+ return true;
}
+ //set the frameProxy Flag:
+ var frameProxyOk = false;
/* setup a iframe request hash */
$.proxy.doFrameProxy = function( reqObj ){
var hashPack = {
//we can't update src's so we have to remove and add all the time :(
//@@todo we should support frame msg system
$j('#frame_proxy').remove();
- $j('body').append('<iframe id="frame_proxy" name="frame_proxy" ' +
+ $j('body').append('<iframe style="display:none" id="frame_proxy" name="frame_proxy" ' +
'src="' + $.proxy.server_frame +
'#' + escape( JSON.stringify( hashPack ) ) +
'"></iframe>' );
+
+ //add an onLoad hook:
+ $j('#frame_proxy').get(0).onload = function(){
+ //add a 5 second timeout for setting up the nested child callback (after page load)
+ setTimeout(function(){
+ if( !frameProxyOk ){
+ //we timmed out no api proxy (should make sure the user is "logged in")
+ //for now let the implementation call proxyNotReadyDialog
+ $.proxy.callback ( false );
+ }
+ }, 5000);
+ }
}
-
+ $.proxy.proxyNotReadyDialog = function(){
+ var btn = {};
+ btn[ gM('mwe-re-try') ] = function(){
+ $j.addLoaderDialog( gM('mwe-re-trying') );
+ $.proxy.doFrameProxy( lastApiReq );
+ }
+ btn[ gM('mwe-cancel') ] = function(){
+ $j.closeLoaderDialog();
+ }
+ var pUri = parseUri( $.proxy.server_frame);
+ //this is sort of a temporary hack if we change the MediaWiki:ApiProxy key
+ //we will have to deal with that here as well:
+ var login_url = pUri.protocol +'://'+ pUri.host +
+ pUri.path.replace( 'MediaWiki:ApiProxy', 'Special:UserLogin');
+ $j.addDialog( gM('mwe-proxy-not-ready'), gM('mwe-please-login', login_url ) +
+ '<p style="font-size:small">' + gM('mwe-remember-loging') + '</p>',
+ btn
+ )
+ }
+ var lastApiReq = {};
/* the do_api_request with callback: */
$.proxy.doRequest = function( reqObj, callback){
js_log("doRequest:: " + JSON.stringify( reqObj ) );
+ lastApiReq = reqObj;
//setup the callback:
$.proxy.callback = callback;
//do the proxy req:
* The nested iframe action that passes its msg back up to the top instance
*/
$.proxy.nested = function( hashResult ){
- js_log( 'got $.proxy.nested callback!! :: ' + hashResult );
+ //js_log( '$.proxy.nested callback :: ' + hashResult );
+ frameProxyOk = true;
//try to parse the hash result:
try{
var rObj = JSON.parse( unescape( hashResult ) );
}catch (e) {
js_log("Error could not parse hashResult");
}
- //hide the loader if the initial state = ready msg is fired:
- if( rObj && rObj.state == 'ready')
- $j.closeLoaderDialog();
+ //special callback to frameProxyOk flag (not an api result, don't call callback)
+ if( rObj.state == 'ok')
+ return ;
+
//if all good pass it to the callback:
$.proxy.callback( rObj );
}
return false;
}
- var domain = parseUri( document.URL ).host;
+ var domain = aObj.cd;
var nested_frame_src = 'http://' + aObj.cd + aObj.cfp;
//check the master whitelist
for(var i in pConf.master_whitelist){
});*/
//if still not found:
- js_log("domain " + domain + " not approved");
+ js_log("domain " + domain + " not approved");
+
+ //offer the user the ability to "approve" requested domain save to their user page
function doNestedProxy( reqObj ){
js_log("doNestedProxy to: " + nested_frame_src);
- var outputhash = escape( JSON.stringify( reqObj ) );
- //check if its just a "echo" request (no need to hit the api)
- if( reqObj.init && reqObj.init == 'echo'){
- doNestedFrame( {'state': 'ready', "echo": true } );
- }else{
- //add some api stuff:
- reqObj['format'] = 'json';
- //process the api request
- $j.get(wgScriptPath + '/api' + wgScriptExtension,
- reqObj,
- function( data ){
- js_log("Proxy GOT Res: " + data );
- //put it into the nested frame hash string:
- doNestedFrame( JSON.parse( data ) );
- }
- );
- }
+ //output iframe prior to running api request
+ //(so we can fail faster / cache the nested page / simotaniusly load things)
+ doNestedFrame ( 'nested_ok' , {'state':'ok'});
+
+ var outputhash = escape( JSON.stringify( reqObj ) );
+ //add some api stuff:
+ reqObj['format'] = 'json';
+ //process the api request
+ $j.post(wgScriptPath + '/api' + wgScriptExtension,
+ reqObj,
+ function( data ){
+ //js_log("Proxy GOT Res: " + data );
+ //put it into the nested frame hash string:
+ doNestedFrame( 'nested_push', JSON.parse( data ) );
+ }
+ );
}
//add the doNestedFrame iframe:
- function doNestedFrame( resultObj ){
+ function doNestedFrame( nestname, resultObj ){
$j('#nested_push').remove();
//setup the nested proxy that points back to top domain:
$j('body').append( '<iframe id="nested_push" name="nested_push" ' +
* checks for jQuery and adds the $j noConflict var
*/
jQueryCheck: function( callback ) {
- //js_log( 'jQueryCheck::' );
+ js_log( 'jQueryCheck::' );
// Skip stuff if $j is already loaded:
if( _global['$j'] && callback )
callback();
// Check the jQuery flag. This way, when remote embedding, we don't load jQuery
// unless js2AddOnloadHook was used or there is video on the page.
runQueuedFunctions: function() {
- var _this = this;
- this.doneReadyEvents = true;
+ js_log("runQueuedFunctions");
+ var _this = this;
this.jQueryCheck( function() {
+ this.doneReadyEvents = true;
_this.runReadyEvents();
});
},
}
//js2AddOnloadHook: ensure jQuery and the DOM are ready
function js2AddOnloadHook( func ) {
+ js_log("js2AddOnloadHook::" + mvJsLoader.doneReadyEvents);
// If we have already run the DOM-ready function, just run the function directly:
if( mvJsLoader.doneReadyEvents ) {
// Make sure jQuery is there:
/*********** INITIALIZATION CODE *************
* set DOM-ready callback to init_mv_embed
*********************************************/
-// for Mozilla browsers
+// for Mozilla / modern browsers
if ( document.addEventListener ) {
- document.addEventListener( "DOMContentLoaded", function(){ mwdomReady() }, false );
-} else {
- // Use the onload method instead when DOMContentLoaded does not exist
- window.onload = function() { mwdomReady() };
+ document.addEventListener( "DOMContentLoaded", mwdomReady, false );
}
-/*
- * Should deprecate and use jquery.ui.dialog instead
- */
-function mv_write_modal( content, speed ) {
- $j( '#modalbox,#mv_overlay' ).remove();
- $j( 'body' ).append(
- '<div id="modalbox" style="background:#DDD;border:3px solid #666666;font-size:115%;' +
- 'top:30px;left:20px;right:20px;bottom:30px;position:fixed;z-index:100;">' +
- content +
- '</div>' +
- '<div id="mv_overlay" style="background:#000;cursor:wait;height:100%;left:0;position:fixed;' +
- 'top:0;width:100%;z-index:5;filter:alpha(opacity=60);-moz-opacity: 0.6;' +
- 'opacity: 0.6;"/>');
- $j( '#modalbox,#mv_overlay' ).show( speed );
+var temp_f;
+if( window.onload ) {
+ temp_f = window.onload;
}
-function mv_remove_modal( speed ) {
- $j( '#modalbox,#mv_overlay' ).remove( speed );
+// Use the onload method as a backup (mwdomReady hanndles dobule init calls)
+window.onload = function () {
+ if( temp_f )
+ temp_f();
+ mwdomReady();
}
/*
* @param mode is either 'server' or 'client'
*/
$.apiProxy = function( mode, pConf, callback ){
- js_log('do apiProxy setup');
- $.addLoaderDialog( gM('mwe-apiproxy-setup') );
+ js_log('do apiProxy setup');
mvJsLoader.doLoad( [
'$mw.proxy',
'JSON'
], function(){
- $mw.proxy[mode]( pConf, callback );
+ //do the proxy setup or
+ if( mode == 'client'){
+ //just do the setup (no callbcak for client setup)
+ $mw.proxy.client( pConf );
+ if( callback )
+ callback();
+ }else if( mode=='server' ){
+ //do the request with the callback
+ $mw.proxy.server( pConf , callback );
+ }
});
}
//non selector based add-media-wizard direct invocation with loader
/*
* The Firefogg jQuery function:
* @@note This Firefogg invocation could be made to work more like real jQuery plugins
- */
+ */
+ var queuedFirefoggConf = {};
$.fn.firefogg = function( iObj, callback ) {
if( !iObj )
iObj = {};
var sElm = $j( this.selector ).get( 0 );
if( sElm['firefogg'] ) {
if( sElm['firefogg'] == 'loading' ) {
- js_log( "Error: called firefogg operations on Firefogg selector that is " +
- "not done loading" );
+ js_log( "Queued firefogg operations ( firefogg " +
+ "not done loading ) " );
+ $j.extend( queuedFirefoggConf, iObj );
return false;
}
// Update properties
myFogg.doRewrite( callback );
var selectorElement = $j( iObj.selector ).get( 0 );
selectorElement['firefogg'] = myFogg;
+
+ js_log('pre:'+ selectorElement['firefogg']['firefogg_form_action'])
+ if(queuedFirefoggConf)
+ $j.extend(selectorElement['firefogg'], queuedFirefoggConf);
+ js_log('post:'+ selectorElement['firefogg']['firefogg_form_action'])
}
});
}
$.addDialog = function ( title, msg_txt, btn ){
$('#mwe_tmp_loader').remove();
//append the style free loader ontop:
- $('body').append('<div id="mwe_tmp_loader" title="' + title + '" >' +
+ $('body').append('<div id="mwe_tmp_loader" style="display:none" title="' + title + '" >' +
msg_txt +
'</div>');
//turn the loader into a real dialog loader:
$('#mwe_tmp_loader').dialog({
bgiframe: true,
draggable: false,
- resizable: false,
- height: 140,
+ resizable: false,
modal: true,
+ width:400,
buttons: btn
});
});
if( !options.data['action'] )
options.data['action'] = 'query';
- // js_log('do api req: ' + options.url +'?' + jQuery.param(options.data) );
- // Build request string
- if( parseUri( document.URL ).host == parseUri( options.url ).host ) {
+ // js_log('do api req: ' + options.url +'?' + jQuery.param(options.data) );
+ if( options.url == 'proxy' && $mw.proxy){
+ //assume the proxy is already "setup" since $mw.proxy is defined.
+ // @@todo we probably integrate that setup into the api call
+ $mw.proxy.doRequest( options.data, callback);
+
+ }else if( parseUri( document.URL ).host == parseUri( options.url ).host ) {
// Local request: do API request directly
$j.ajax({
type: "POST",
function js_error( string ) {
alert( string );
return false;
-}
+}
\ No newline at end of file
<script type="text/javascript" >
//HARD coded local test:
-var remote_wiki_host = 'http://127.1.1.100';
-var remote_script_path = '/wiki_trunk';
+var remote_wiki_host = 'http://test.wikipedia.org';
+var remote_script_path = '/w';
js2AddOnloadHook( function(){
$j('#hostName').text( remote_wiki_host );
function(){
//callback function here:
$j('#setupDone').show('slow');
- $j('#doAppendCat').click( doCatAppend );
+ $j('#doHello').click( doHello );
+ $j('#doAppend').click(doAppend);
}
);
});
-function doCatAppend(){
- js_log('append cat to User page');
- //first get our user name:
+function doHello(){
+ js_log('to a hello user');
+ $j('#helloTarget').html( mv_get_loading_img() );
+ //first get the user name:
+ getUserName(function( user_name ){
+ $j('#helloTarget').hide().text( user_name ).fadeIn('slow');
+ });
+ return false;
+}
+function getUserName( callback ){
var rObj = {
'action':'query',
'meta':'userinfo'
}
//we use normal do_api_req with keywork 'proxy' for the url
$mw.proxy.doRequest( rObj,
- function(data){
+ function( data ){
+ //if we have no data proxy is not setup?
+ if(!data){
+ $mw.proxy.proxyNotReadyDialog();
+ }
//now we get the data back for that domain
if( !data.query || !data.query.userinfo ){
js_log("Error no query.userinfo ");
return false;
- }
- if( data.query.userinfo.id == 0 ){
- var btn = {};
- btn['try again'] = function(){
- doCatAppend();
- }
- btn['cancel'] = function(){
- $j(this).close();
- }
- $j.addDialog("Not logged in",
- "Are you logged in on" + remote_wiki_host + " ? Please loggin",
- btn
- )
- }else{
- $j('#helloTarget').hide().text( data.query.userinfo.name ).fadeIn('slow');
}
+ callback( data.query.userinfo.name );
}
);
- return false;
+}
+
+//simple "hello from api proxy" append on talk page
+function doAppend(){
+ $j('#appendTarget').html( mv_get_loading_img() );
+ //get user name
+ getUserName(function(userName){
+ var eTitle = 'User_talk:' + userName;
+ //get a edit token
+ get_mw_token(eTitle, 'proxy', function( token ){
+ js_log("got token: " + token) ;
+ var aReq = {
+ 'action':'edit',
+ 'title': eTitle,
+ 'summary': "Api proxy test edit",
+ 'appendtext': "\n\n==== Hello from Api proxy At: " + Date() + " ====",
+ 'token': token
+ }
+ do_api_req({
+ 'data': aReq,
+ 'url': 'proxy'
+ },function(result){
+ if(result.edit && result.edit.newrevid){
+ $j('#appendTarget').html( "success: " + JSON.stringify ( result) );
+ url = remote_wiki_host + remote_script_path + '/index.php/';
+ url+= result.edit.title.replace(' ', '_');
+ $j('#appendTarget').append( '<br><a target="_new" href="' + url + '">visit page</a>' );
+ }else{
+ $j('#appendTarget').html( "falied: " + JSON.stringify ( result) );
+ }
+ });
+
+ });
+ });
}
</script>
<body>
<h3> Simple API proxy testing system </h3>
-<div id="setupProxy">Setting up Proxy ... ( <span id="hostName"></span> )</div>
+<div id="setupProxy">Proxy for: <span id="hostName"></span> <br><span style="font-size:small">( be sure to enable the mwEmbed gadget or add importScriptURI( 'path_to_local_mw_install' + /js2/remoteMwEmbed.js ) to your User skin .js page </span></div>
<div id="setupDone" style="display:none;">
-<br> <a href="#" id="doAppendCat" >Hello User</a> <span id="helloTarget"><span>
-<br> Some other fun api stuff here...
+ <br> <a href="#" id="doHello" >Hello User:</a> <span id="helloTarget"></span>
+ <br><br><br> <a href="#" id="doAppend">Append Msg to Talk page:</a>
+ <div id="appendTarget"></div>
</div>
</body>
// Add media wizard
if( wgAction == 'edit' || wgAction == 'submit' ) {
load_mv_embed( function() {
- importScriptURI( mwEmbedHostPath + '/editPage.js' + reqAguments );
+ loadExternalJs( mwEmbedHostPath + '/editPage.js' + reqAguments );
} );
}
// Firefogg integration
if( wgPageName == "Special:Upload" ){
load_mv_embed( function() {
- importScriptURI( mwEmbedHostPath + '/uploadPage.js' + reqAguments );
+ loadExternalJs( mwEmbedHostPath + '/uploadPage.js' + reqAguments );
} );
}
// Special api proxy page
- if( wgPageName == 'MediaWiki:ApiProxy' ){
+ if( wgPageName == 'MediaWiki:ApiProxy' ){
var wgEnableIframeApiProxy = true;
load_mv_embed( function() {
- importScriptURI( mwEmbedHostPath + '/ApiProxyPage.js' + reqAguments );
+ js_log("Wiki:ApiProxy::");
+ loadExternalJs( mwEmbedHostPath + '/apiProxyPage.js' + reqAguments );
});
}
function getRemoteEmbedPath() {
for( var i = 0; i < document.getElementsByTagName( 'script' ).length; i++ ) {
var s = document.getElementsByTagName( 'script' )[i];
- if( s.src.indexOf( 'remoteMwEmbed.js' ) != -1 ) {
+ if( s.src.indexOf( '/remoteMwEmbed.js' ) != -1 ) {
var reqStr = '';
var scriptPath = '';
if( s.src.indexOf( '?' ) != -1) {
reqStr = s.src.substr( s.src.indexOf( '?' ) );
- scriptPath = s.src.substr( 0, s.src.indexOf( '?' ) ).replace( 'remoteMwEmbed.js', '' );
+ scriptPath = s.src.substr( 0, s.src.indexOf( '?' ) ).replace( '/remoteMwEmbed.js', '' );
} else {
- scriptPath = s.src.replace( 'remoteMwEmbed.js', '' )
+ scriptPath = s.src.replace( '/remoteMwEmbed.js', '' )
}
// Use the external_media_wizard path:
return [scriptPath, reqStr];
}
function load_mv_embed( callback ) {
+ if(console.log)
+ console.log( 'load_mv_embed');
// Inject mv_embed if needed
if( typeof mvEmbed == 'undefined' ) {
importScriptURI( mwEmbedHostPath + '/mwEmbed/mv_embed.js' + reqAguments );
* This script is run on [[Special:Upload]].
* It controls the invocation of the mvUploader class based on local config.
*/
+
js2AddOnloadHook( function() {
+ js_log("never ran js2hook");
mwUploadHelper.init();
-} );
+});
+
var mwUploadFormTarget = '#mw-upload-form';
// Set up the upload form bindings once all DOM manipulation is done
var mwUploadHelper = {
$j( '#wpUploadFileURL' ).attr( 'disabled', set );
// If Firefogg is enabled, toggle action according to wpSourceTypeFile selection
- if( wgEnableFirefogg ) {
+ if( wgEnableFirefogg ) {
$j( '#wpUploadFile' ).firefogg({
'firefogg_form_action': $j( '#wpSourceTypeFile' ).attr( 'checked' )
} );
'warn_target': '#wpDestFile-warning'
} );
}
-}
+}
\ No newline at end of file